//
//  QrCodeView.swift
//  AirlineReservation
//
//  Created by Kevin on 2020/2/19.
//  Copyright © 2020 Kevin. All rights reserved.
//

import UIKit

class QrCodeView: UIView {
    
    // 公司名称
    private let companyName = UILabel(title: "", color: UIColor.black, size: 18, align: .center)
    // 提示
    private let tip = UILabel(title: "扫一扫上面的二维码图案，快速开票", color: UIColor.gray, size: 12, align: .center)
    // 二维码图片
    let img = UIImageView()
    
    public var resetCompanyName:String? {
        didSet {
            companyName.text = resetCompanyName
        }
    }
    
    public var resetQrMessage:String? {
        didSet {
            img.image = QrCodeImgUtil.shareInstance.generateQRCodeImg(resetQrMessage!, qrImgName: "main_avatar_97x97")
        }
    }
    
    override func layoutSubviews() {
        // 公司名称
        companyName.frame = CGRect(x: 0, y: MARGIN30, width: frame.width, height: MARGIN20)
        addSubview(companyName)
        // 二维码图片
        let imgW = frame.width - MARGIN80
        let imgX = (frame.width - imgW) * 0.5
        let imgY = companyName.frame.maxY + MARGIN20
        img.frame = CGRect(x: imgX, y: imgY, width: imgW, height: imgW)
        addSubview(img)
        // 提示
        tip.frame = CGRect(x: 0, y: img.frame.maxY + MARGIN20, width: frame.width, height: MARGIN)
        addSubview(tip)
    }
}
